﻿using System.Collections.ObjectModel;
using SvgViewer.Core;

namespace SvgViewer.Entities;

/// <summary>
/// 目录类型
/// </summary>
public enum FolderType
{
    /// <summary>
    /// 目录
    /// </summary>
    Folder,

    /// <summary>
    /// 桌面
    /// </summary>
    Desktop,

    /// <summary>
    /// 磁盘
    /// </summary>
    Disk
}

/// <summary>
/// 目录信息
/// </summary>
public class FolderInfo : NotifyPropertyBase
{
    private bool isExpand;
    private bool isSelected;

    /// <summary>
    /// 获取子目录
    /// </summary>
    public ObservableCollection<FolderInfo> Child { get; internal set; }

    /// <summary>
    /// 构造
    /// </summary>
    public FolderInfo() { }

    /// <summary>
    /// 构造
    /// </summary>
    /// <param name="path">目录路径</param>
    public FolderInfo(string path) : this(path, System.IO.Path.GetDirectoryName(path), FolderType.Folder) { }

    /// <summary>
    /// 构造
    /// </summary>
    /// <param name="path">目录路径</param>
    /// <param name="name">目录名称</param>
    /// <param name="folderType">目录类型</param>
    public FolderInfo(string path, string name, FolderType folderType)
    {
        this.Path       = path;
        this.Name       = name;
        this.FolderType = folderType;
        FolderHandle.Instance.SetFolderInitInfo(this);
    }

    /// <summary>
    /// 获取目录路径
    /// </summary>
    public string Path {
        get;
    }

    /// <summary>
    /// 获取目录名称
    /// </summary>
    public string Name { get; }

    /// <summary>
    /// 获取目录类型
    /// </summary>
    public FolderType FolderType { get; }

    /// <summary>
    /// 获取或设置目录展开状态
    /// </summary>
    public bool IsExpand {
        get => isExpand;
        set =>
            SetValue(ref isExpand, value, nameof(IsExpand), () => {
                if (value && Child?.Count == 1)
                {
                    FolderHandle.Instance.LoadChild(this);
                }
            });
    }

    /// <summary>
    /// 获取或设置目录选中状态
    /// </summary>
    public bool IsSelected {
        get => isSelected;
        set => SetValue(ref isSelected, value, nameof(IsSelected));
    }
}